package com.api.shopapi.service.impl;

import com.api.shopapi.entity.User;
import com.api.shopapi.entity.dto.UserDTO;
import com.api.shopapi.mapper.UserMapper;
import com.api.shopapi.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("UserServiceImplOne")
public class UserServiceImpl implements UserService {


    @Autowired
    private UserMapper userMapper;


    @Override
    public int insert(User user) {
        return  userMapper.insert(user);
    }

    @Override
    public int update(User user) {
        return userMapper.update(user);
    }

    @Override
    public int updateName(User user) {
        return userMapper.updateName(user);
    }

    @Override
    public User getByUserCode(String userCode) {
        return userMapper.getByUserCode(userCode);
    }

    @Override
    public UserDTO getByForUserDTO(String userCode) {
        return userMapper.getByForUserDTO(userCode);
    }


    @Override
    public User getByPhone(String phone) {
        return userMapper.getByPhone(phone);
    }

    @Override
    public
    User getByLoginName(String loginName){
        return userMapper.getByLoginName(loginName);
    }

    @Override
    public User getByPhoneAndPassword(String phone, String password) {
        return userMapper.getByPhoneAndPassword(phone,password);
    }

    @Override
    public
    User getByLoginNameAndPassword(String loginName, String password){
        return userMapper.getByLoginNameAndPassword(loginName,password);
    }

    @Override
    public PageInfo<UserDTO> getListForAdmin(int pageIndex, int pageSize, String governmentCode,String name,String phone) {
        PageHelper.startPage(pageIndex,pageSize);
        List<UserDTO> userDTOList=userMapper.getListForAdmin(governmentCode,name,phone);
        return new PageInfo<>(userDTOList);
    }

    @Override
    public PageInfo<UserDTO> getListForGov(int pageIndex, int pageSize, String governmentCode, String name, String phone) {
        PageHelper.startPage(pageIndex,pageSize);
        List<UserDTO> userDTOList=userMapper.getListForGov(governmentCode,name,phone);
        return new PageInfo<>(userDTOList);
    }

    @Override
    public
    List<User> getListAll(){
        return userMapper.getListAll();
    }

    @Override
    public
    List<UserDTO> listByNamePhone(String name, String phone, String loginName){
        return userMapper.listByNamePhone(name,phone,loginName);
    }


}
